package com.ruoyi.pingan.fymodule.thirdpa.controller;

import com.sdb.util.Base64;
import com.sdb.util.SignUtil;

import java.security.SecureRandom;
import java.util.Random;



public class TestSign {

    public static void main(String[] args) throws Exception {
        String ALG = "DesEde/CBC/PKCS5Padding";

        String fsrc = "/ejzb/4605/CZ2025091946051.txt.enc";

        String key = "UMHvVUd3DpV4RpmCIlKbX5vNSvTecwlm";

        //若要切换成加密，自行将if里的false改为true即可
        if(false){
            Random random = new SecureRandom();
            byte[] bkey = new byte[24];
            random.nextBytes(bkey);
            key = new String(Base64.encode(bkey));
            System.out.println("密码=[" + key + "]");
            String srcFile = fsrc;
            String zipFile = srcFile + ".zip";
            String encFile = srcFile + ".enc";
            // 加压
            SignUtil.compress(srcFile, zipFile);
            // 加密
            SignUtil.encrypt(zipFile, encFile, bkey, ALG, "DesEde", null);
        } else {
            String desFile = fsrc;

            String srcFile = fsrc + ".enc";
            String zipFile = fsrc + ".zip";
            byte[] bkey = Base64.decode(key.getBytes());
            // 解密
            SignUtil.decrypt(srcFile, zipFile, bkey, ALG, "DesEde", null);
            // 解压
            SignUtil.uncompress(zipFile, desFile);
        }
    }


}
